<?php

if(!isset($_SESSION['username'])){
		echo "<script>alert('请登录！');window.location.href='login.php?m=admin&c=manage'</script>";die;
	}

//权限管理
authonity($con);

	$id = $_GET['id'];

	$mid = $_GET['mid'];

	$aid = $_GET['aid'];
	
//	dbselect($con,'products','*',"id=$id");
	$sql = "select * from products where id=$id";
	$query = mysqli_query($con,$sql);
	
	$data = mysqli_fetch_assoc($query);
		
	$name = $data['name'];
	$identification_pro = $data['identification_pro'];
	$intro = $data['intro'];
	$category_id = $data['category_id'];
	
	
	
	
	
	 //dbupdate($con,$table,$field,$where=null)

	//提交修改
	if($_POST){

		if($_POST['name'] == ''){
			echo "<script>alert('名称不可为空');</script>";
		}elseif($_POST['identification_pro'] == ''){
			echo "<script>alert('产品编号不可为空');</script>";
		}elseif($_POST['intro']==''){
			echo "<script>alert('产品介绍不可为空');</script>";
		}else{







		$field['name'] = htmlspecialchars(trim($_POST['name']));
		$field['identification_pro'] = htmlspecialchars(trim($_POST['identification_pro']));
		$field['intro'] = htmlspecialchars_decode(trim($_POST['intro']));
		$field['category_id'] = $_POST['category_id'];


		if(!empty($_FILES['pro_img'])){
				$imgsrc = $_FILES['pro_img'];
				if($imgsrc['size'] != 0){
					$path = uploadsIMG($imgsrc);
					$img = overSize_thumb($path);

					$ho_thumb = thumb($img,250,250,'home');
					$ad_thumb = thumb($img,50,50);


					$img_path[] = $img;
					$img_path[] = $ho_thumb;
					$img_path[] = $ad_thumb;
					$field['img_path'] = json_encode($img_path);

				}
			}

			$detail1_img = $_FILES['detail1'];
			$detail2_img = $_FILES['detail2'];
			$detail3_img = $_FILES['detail3'];

			if($detail1_img['size'] != 0){

				$detail1 = uploadsIMG($detail1_img);

				if($detail2_img['size'] != 0){

					$detail2 = uploadsIMG($detail2_img);

					if($detail3_img['size'] != 0){

						$detail3 = uploadsIMG($detail3_img);

					}
				}
			}
			if(isset($detail1)){
				$img_detail[] = $detail1;
				if(isset($detail2)){
					$img_detail[] = $detail2;
					if(isset($detail3)){
						$img_detail[] = $detail3;
					}
				}

				$field['img_detail'] = json_encode($img_detail);
			}

				


		$query = dbupdate($con,'products',$field,"id=$id");
		if($query){
			echo "<script>alert('修改成功');location.href='index.php?m=admin&c=product&mid=17&aid=$aid'</script>";
		}else{
			echo "<script>alert('修改失败');location.href='index.php?id={$id}&m=admin&c=product&v=pro_upd&mid=$mid&aid=$aid'</script>";
		}
	}
}


$pro_cate = dbselect($con,'category','category_name,id','pid=4');

assign('pro_cate',$pro_cate);

assign('name',$name);

assign('identification_pro',$identification_pro);

assign('intro',$intro);

assign('category_id',$category_id);



?>